#!/usr/bin/php
<?php
$connect = mysql_connect("localhost","beerwatch","beerwatch") or die(mysql_error());
$db = mysql_select_db("beerwatch",$connect);
$file=$argv[0];
$ti = explode("_",$file);
$temp_index=$ti[1];

if ($argc == 2) {
	if ($argv[1] == "config") {
		echo "graph_title Heat On for index: $temp_index\n";
		echo "graph_vlabel Heat Index\n";
		echo "graph_category Beerwatch\n";
		echo "graph_info A visulization of the heat on/off cycles\n";
		echo "heat.label Heat for index: $temp_index\n";
	}
	exit;
}

$sql = "select gpio from gpiotoheat where temp_index=\"$temp_index\"";
$r = mysql_query($sql,$connect);
$row = mysql_fetch_array($r);
$d = $row[0];


$fp = fopen("/sys/class/gpio/gpio".$d."/value","r");
$on = fread($fp,4096);
fclose($fp);
$on = trim($on);

echo "heat.value " . $on ."\n";
?>
